package com.departmentstore.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import javax.persistence.*;
import java.io.Serializable;

@Data
@Entity
@Table(name = "department_product")
public class DepartmentProduct implements Serializable {
    @EmbeddedId
    private DepartmentProductId id;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("departmentId")
    @JoinColumn(name = "department_id")
    @JsonIgnore
    private Department department;

    @ManyToOne(fetch = FetchType.LAZY)
    @MapsId("productId")
    @JoinColumn(name = "product_id")
    @JsonIgnore
    private Product product;

    @Column(name = "quantity")
    private Integer quantity;

    public String getDepartmentId() {
        return id != null ? id.getDepartmentId() : null;
    }

    public void setDepartmentId(String departmentId) {
        if (id == null) {
            id = new DepartmentProductId();
        }
        id.setDepartmentId(departmentId);
    }

    public String getProductId() {
        return id != null ? id.getProductId() : null;
    }

    public void setProductId(String productId) {
        if (id == null) {
            id = new DepartmentProductId();
        }
        id.setProductId(productId);
    }
} 